#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 55;
int n, m;
int g[N][N];
bool st[N][N];
PII q[N * N];
int dx[] = { 0,-1,0,1 };
int dy[] = { -1,0,1,0 };
int bfs(int x, int y)
{
	int hh = 0, tt = 0;
	q[0] = { x,y };
	st[x][y] = 1;
	int ans = 0;
	while (hh <= tt) {
		PII t = q[hh++];
		ans++;
		for (int i = 0; i < 4; i++) {
			int a = t.x + dx[i];
			int b = t.y + dy[i];
			if (a < 0 || a >= n || b < 0 || b >= m) {
				continue;
			}
			if (st[a][b]) {
				continue;
			}
			if (g[t.x][t.y] >> i & 1) {
				continue;
			}
			q[++tt] = { a,b };
			st[a][b] = 1;
		}
	}
	return ans;
}
int main()	
{
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> g[i][j];
		}
	}
	int ans = 0;
	int area = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (!st[i][j]) {
				ans++;
				area = max(area, bfs(i, j));
			}
		}
	}
	cout << ans << " " << area << endl;
	return 0;
}